import { DirUtil } from "./DirUtil";
import { Md5Util } from "./Md5Util";
import { FileIoUtil } from "./FileIOUtil";
import { Main } from "../Main";
import { SvnUtil } from "./SvnUtil";

/**
 * 快速文件改变检测工具
 * @author 赵占涛
 */
export class FastFileChangeUtil {
    /** 
     * 找到变更的文件(变更的，新增的，删除的)
     */
    static changed(path:string, cb:(fileChange:string[], fileAdd:string[], fileDelete:string[])=>void) {
        SvnUtil.status(path, (status)=>{
            let fileStatusArr = status.split("\n");
            console.log(fileStatusArr);

            let dtChange:{[key:string]:true} = {};
            let dtAdd:{[key:string]:true} = {};
            let dtDelete:{[key:string]:true} = {};
            for (let i = 0; i < fileStatusArr.length; i++) {
                const one = fileStatusArr[i];
                if (one.startsWith("?") || one.startsWith("A")) {
                    dtAdd[one.substr(8)] = true;
                } else if (one.startsWith("!") || one.startsWith("D")) {
                    dtDelete[one.substr(8)] = true;
                } else if (one.startsWith("M")) {
                    dtChange[one.substr(8)] = true;
                }  
            }
            cb(Object.keys(dtChange),Object.keys(dtAdd),Object.keys(dtDelete),);
        });
    }
}